package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Items;
import com.ruoyi.system.service.IItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 存货档案Controller
 * 
 * @author ruoyi
 * @date 2025-10-16
 */
@RestController
@RequestMapping("/system/items")
public class ItemsController extends BaseController
{
    @Autowired
    private IItemsService itemsService;

    /**
     * 查询存货档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(Items items)
    {
        startPage();
        List<Items> list = itemsService.selectItemsList(items);
        return getDataTable(list);
    }

    /**
     * 导出存货档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:export')")
    @Log(title = "存货档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Items items)
    {
        List<Items> list = itemsService.selectItemsList(items);
        ExcelUtil<Items> util = new ExcelUtil<Items>(Items.class);
        util.exportExcel(response, list, "存货档案数据");
    }

    /**
     * 获取存货档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") String itemId)
    {
        return success(itemsService.selectItemsByItemId(itemId));
    }

    /**
     * 新增存货档案
     */
    @PreAuthorize("@ss.hasPermi('system:items:add')")
    @Log(title = "存货档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Items items)
    {
        return toAjax(itemsService.insertItems(items));
    }

    /**
     * 修改存货档案
     */
    @PreAuthorize("@ss.hasPermi('system:items:edit')")
    @Log(title = "存货档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Items items)
    {
        return toAjax(itemsService.updateItems(items));
    }

    /**
     * 删除存货档案
     */
    @PreAuthorize("@ss.hasPermi('system:items:remove')")
    @Log(title = "存货档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable String[] itemIds)
    {
        return toAjax(itemsService.deleteItemsByItemIds(itemIds));
    }
}
